package com.beadwallet.alarm.contans;

import com.beadwallet.alarm.util.StringUtil;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by master on 16-11-15.
 */
public class ContansData {


    public static final String FLAGTOTCORD = "FLAGTOT";
    /**
     * 报警总开关
     */
    public static volatile boolean FLAGTOT = true;

    /**
     * 队列自身的总控开关
     */
    public static volatile boolean QUEUEFLAG = true;

    public static Map<Object, Map<Long, Long>> ACTIVERECORD = new ConcurrentHashMap();
    /**
     * 指定异常排除报警
     */
    public static Set<Integer> EXCLUDE = Collections.synchronizedSet(new HashSet());


    /**
     * 邮件标示
     */
    public static final int MAILFLAG = 0;
    /**
     * 微信标示
     */
    public static final int WECHATFLAG = 1;
    /**
     * 地址不合法code
     */
    public static final String ADDRESSEXCEPTION = "999";
    /**
     * 警报邮件发送失败
     */
    public static final String ALARMSENDERROR = "900";
    /**
     * 邮件发送成功
     */
    public static final String MAILSENDSUCCESS = "901";
    /**
     * 网络异常稍后补发
     */
    public static final String INTELBLOKING = "902";
    /**
     * 未知错误
     */
    public static final String ERROR = "903";
    /**
     * commonAttr 执行参数
     */
    public static final String COMMONQUERY = "query";
    
    public static final String COMMONMSG = "msgInfo";
    
    public static final String COMMONWEBPUT = "put";

    public static final String COMMONWEBREMOVE = "remove";


    /**
     * @param flag 修改总开关操作
     */
    public static void modifyFlagTot(boolean flag, long time) {
        FLAGTOT = flag;
        if (time > 0l && flag == false) {
            Map<Long, Long> totCord = new HashMap<>();
            totCord.put(System.currentTimeMillis(), time * 60 * 1000);
            ACTIVERECORD.put(FLAGTOTCORD, totCord);
        }
    }

    /**
     * 增加排除报警的异常
     *
     * @param exceptionCode
     */
    public static void addExclude(int exceptionCode, long time) {
        if (time > 0l) {
            Map<Long, Long> totCord = new HashMap<>();
            totCord.put(System.currentTimeMillis(), time * 60 * 1000);
            ACTIVERECORD.put(exceptionCode, totCord);
        }
        EXCLUDE.add(exceptionCode);
    }


    /**
     * 移除排除报警的异常
     *
     * @param exceptionCode
     */
    public static void removeExclude(int exceptionCode) {
        if (StringUtil.isNotEmpty(ACTIVERECORD.get(exceptionCode))) {
            ACTIVERECORD.remove(exceptionCode);
        }
        EXCLUDE.remove(exceptionCode);
    }
}
